// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

import Hero from "../hero";
import {wxUtils} from "../wx/wxUtils";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Killboard extends cc.Component {

  private _hero: cc.Node = null;

  @property(cc.Label)
  txtKill: cc.Label = null;

  @property(cc.Label)
  txtScore: cc.Label = null;

  heroScript: Hero;

  onLoad() {
  }


  set hero(value: cc.Node) {
    this._hero = value;
    this.heroScript = this._hero.getComponent(Hero)
    this._hero.on('kill', this.onKill, this);
    this._hero.on('score', this.onScore, this);
  }

  private onKill(e) {
    this.txtKill.string = e.detail + ''
  }

  private onScore(e) {
    wxUtils.postMessage({cmd: 'get-score', score: e.detail + ''})
    this.txtScore.string = e.detail + ''
  }

  reset() {
    this.txtKill.string = '0'
    this.txtScore.string = '0'
  }
}
